package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppCommentReply;
import com.vf.admin.miaodong.entity.AppUserLoginRecord;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * 用户登录
 */
@Repository
public class AfterUserLoginRecordDao extends BaseDao<AppUserLoginRecord> {

    /**
     * 综合查询列表
     */
    public List<AppUserLoginRecord> list(Map<String,Object> paraMap, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_user_login_record where 1=1  ");
        if(StringEx.isNotNull(paraMap.get("startDate"))){
            sbStr.append(" and DATE_FORMAT(logintime, '%Y-%m-%d')  >=  ? ");
            paramList.add(paraMap.get("startDate"));
        }
        if(StringEx.isNotNull(paraMap.get("endDate"))){
            sbStr.append(" and DATE_FORMAT(logintime, '%Y-%m-%d')  <=  ? ");
            paramList.add(paraMap.get("endDate"));
        }
        if(StringEx.isNotNull(paraMap.get("nick"))){
            sbStr.append(" and nick like ? ");
            paramList.add("%"+paraMap.get("nick")+"%");
        }
        if(StringEx.isNotNull(paraMap.get("phone"))){
            sbStr.append(" and phone = ? ");
            paramList.add(paraMap.get("phone"));
        }
        if(StringEx.isNotNull(paraMap.get("deviceModel"))){
            sbStr.append(" and deviceModel like ? ");
            paramList.add("%"+paraMap.get("deviceModel")+"%");
        }
        if(StringEx.isNotNull(paraMap.get("packageName"))){
            sbStr.append(" and packageName = ? ");
            paramList.add(paraMap.get("packageName"));
        }
        sbStr.append(" order by logintime desc");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppUserLoginRecord.class,splitPage);
    }


    /**
     * 详情
     */
    public AppUserLoginRecord get(Integer id) {
        if (id==null || id<=0) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_user_login_record where id = ?  ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppUserLoginRecord.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppUserLoginRecord appUserLoginRecord) {
        if (appUserLoginRecord!=null && appUserLoginRecord.getId() != null && appUserLoginRecord.getId() > 0) {
            this.update(appUserLoginRecord);
        } else {
            appUserLoginRecord.setId(this.add(appUserLoginRecord));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id==null || id <= 0) {
            return;
        }
        String sql = "delete  from app_user_login_record where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

}
